package com.cyy.activitylifecycleyanalysisdemo.activity;

import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.cyy.activitylifecycleyanalysisdemo.R;

/**
 * /**
 * <pre>
 *     author : YYCHEN
 *     e-mail : offengsiveyy@163.com
 *     time   : 2018/03/15
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public abstract class AbstractBaseActivity extends AppCompatActivity implements View.OnClickListener {

    TextView tv_activityName;
    Button btn_default;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(getLogTag(), "onCreate");

        int layoutResId = getContentLayoutResId();
        if(layoutResId == R.layout.activity_default_layout){
            setContentView(layoutResId);
            tv_activityName = findViewById(R.id.tv_activityName);
            tv_activityName.setText(getActivityDecs());

            btn_default = findViewById(R.id.btn_default);
            btn_default.setText(getDefaultBtnText());
            btn_default.setOnClickListener(this);
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d(getLogTag(), "onRestart");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d(getLogTag(), "onStart");
    }

    @Override
    protected void onPostCreate(@Nullable Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        Log.d(getLogTag(), "onPostCreate");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(getLogTag(), "onResume");
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();
        Log.d(getLogTag(), "onPostResume");
    }

    @Override
    public void onUserInteraction() {
        super.onUserInteraction();
        Log.d(getLogTag(), "onUserInteraction");
    }

    @Override
    protected void onUserLeaveHint() {
        super.onUserLeaveHint();
        Log.d(getLogTag(), "onUserLeaveHint");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d(getLogTag(), "onPause");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d(getLogTag(), "onStop");
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        Log.d(getLogTag(), "onAttachedToWindow");

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d(getLogTag(), "onDestroy");

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Log.d(getLogTag(), "onSaveInstanceState");
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        Log.d(getLogTag(), "onRestoreInstanceState");
    }

    protected abstract @LayoutRes int getContentLayoutResId();
    protected String getActivityDecs(){
        return "no description";
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.btn_default){
            onDefaultButtonClick(v);
        }
    }

    protected void onDefaultButtonClick(View v){}
    protected String getDefaultBtnText(){
        return "example";
    }
    protected abstract  String getLogTag();
}
